package com.fruit.auth.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.fruit.auth.dao.PrivilegeDao;
import com.fruit.auth.model.Privilege;
import com.fruit.dao.impl.BaseDaoImpl;

@Repository("privilegeDao")
public class PrivilegeDaoImpl extends BaseDaoImpl<Privilege> implements PrivilegeDao
{
	public List<Privilege> findPrivilegesForUser(Serializable userId)
	{
		String hql="select distinct p from Privilege p, RolePrivilege rp, UserRole ur, Role r where rp.privilege=p and ur.role=rp.role and rp.role=r"
				+" and ur.user.id=? and r.roleEnabled=true and p.privilegeEnabled=true";
		return findEntityByHql(hql, userId);
	}
	
	public List<Privilege> findPrivilegesForRole(Serializable roleId)
	{
		String hql="select distinct p from Privilege p, RolePrivilege rp"
				+ "where rp.privilege=p and rp.role.id=? and p.privilegeEnabled=true";
		return findEntityByHql(hql, roleId);
	}

}
